let util = require('../../../../common/util/util.js')

Page({
    data: {
        xData : {} ,
        xOotd : {} ,
        week : {} ,
        turn : false ,
        pid : '',
        uuid:''
    },
    onLoad: function (options) {
        let that = this
        that.setData({
            week : options.week ,
            turn : options.turn ,
            height : options.height ,
            pid : options.pid,
            uuid: options.uuid
        })
        console.log(that.data.uuid)
        that.xInit(options.id)
    },

    xInit : async function (id) {
        let that = this
        if(id === 'all'){
            await wx.cloud.callFunction({
                name: 'scale_manage',
                data: {
                    action: "get_scale_info",
                    return_data_type: 3,
                    scale_number: 'phq9'
                },
                success: res => {
                    let phq = res.result
                    wx.cloud.callFunction({
                        name: 'scale_manage',
                        data: {
                            action: "get_scale_info",
                            return_data_type: 3,
                            scale_number: 'gad7'
                        },
                        success: xs => {
                            let gad = xs.result
                            console.log(phq , gad)
                            let data = phq.subjects.concat(gad.subjects)
                            console.log(data)
                            phq.subjects = data
                            that.setData({
                                xData : phq ,
                                xOotd : gad
                            })
                        }
                    })
                }
            })
        }else{
            await wx.cloud.callFunction({
                name: 'scale_manage',
                data: {
                    action: "get_scale_info",
                    return_data_type: 3,
                    scale_number: id
                }
            }).then(res => {
                let data = res.result
                that.setData({
                    xData : data
                })
            })
        } 
    }
   
})